<!DOCTYPE html>
<html lang="cn" xmlns:th="http://www.thymeleaf.org">
<head th:include="module/public/include :: mainhead('任务编辑')">
</head>
<body>
	<section>
		<div th:replace="module/public/menu"></div>

		<!-- main content start-->
		<div class="main-content">
			<!--body wrapper start-->
			<div class="wrapper">
				<div class="panel panel-default ">
					<div class="panel-heading template-panel-gray">
						<div class="panel-title">任务维护</div>
					</div>
					<div class="panel-body">
						<div class="container-fluid">
							<div class="row">
								<div class="row_tit">
									<h4>任务信息</h4>
									<div>
										<button class="btn  btn-primary template-btn-green" type="button" onclick="save()">
											<i class="fa fa-save"></i>
											&nbsp;保 存
										</button>
									</div>
								</div>
							</div>
							<div class="row">
								<div class="col-md-12">
									<div class="container-fluid">
										<form id="frmJob">
											<div id="dynFrm"></div>
											<div class="row search-row" style="margin-bottom: 5px;">
												<label for="" class="col-md-1 template-input-label">定时计划:</label>
												<div class="col-md-11">
													<textarea name="cronExpression" cols="2" rows="2" class="form-control"></textarea>
												</div>
											</div>
											<div class="row search-row" style="margin-bottom: 5px;">
												<label for="" class="col-md-1 template-input-label">任务描述:</label>
												<div class="col-md-11">
													<textarea name="description" cols="2" rows="2" class="form-control"></textarea>
												</div>
											</div>
											<div class="row search-row">
												<label for="" class="col-md-1 template-input-label">保存即执行：</label>
												<div class="col-md-3 template-input-label">
													<input type="checkbox">
												</div>
												<label for="" class="col-md-1 template-input-label">是否有返回值：</label>
												<div class="col-md-3 template-input-label">
													<input type="checkbox">
												</div>
												<label for="" class="col-md-1 template-input-label">是否有参数：</label>
												<div class="col-md-3 template-input-label">
													<input type="checkbox" id="isParam">
												</div>
											</div>
											<div class="row search-row" id="divParam" style="margin-bottom: 5px;">
												<label for="" class="col-md-1 template-input-label">参数信息:</label>
												<div class="col-md-11">
													<textarea name="parameters" cols="2" rows="2" class="form-control"></textarea>
												</div>
											</div>
											<input type="hidden" name="id">
										</form>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</section>

	<script type="text/javascript">
	$(function() {
		formDraw();
		
		var urlParm = $.getUrlParams();
		
		if(urlParm.id){
			formload(urlParm.id);
		}
	});
	
	function formDraw(){
		$("#dynFrm").module("form",{
			forms:[
				{key:"name",name:"名称"},
				{key:"key",name:"key"},
				{key:"group",name:"分组"},
				{key:"status",name:"当前状态"},
				{key:"type",name:"服务类型"},
				{key:"msName",name:"微服务"},
				{key:"apiUrl",name:"URL链接"},
				{key:"beanClass",name:"全限定类名"},
				{key:"method",name:"方法名"},
				{key:"createUser",name:"创建人"},
				{key:"createTime",name:"创建时间"},
				{key:"updateTime",name:"修改时间"},
			],
			drawType:'replace',
			row:true,
			rows:3
		});
	}
	
	function formload(id){
		$.ajax({
			url:'[[@{/jobInfo/one}]]',
			type:'get',
			dataType:'json',
			data:{id:id},
			success:function(result){
				if(result.status){
					$.setformElementParams($("#frmJob"),result.detail)
				}
			}
		})
	}
	
	function save(){
		var data = $.getformElementParams($("#frmJob"));
		
		console.log(data);
		
// 		data.parameters = JSON.stringify(data.parameters);
		
		$.ajax({
			url:'[[@{/jobInfo/save1}]]',
			type:'POST',
			dataType:'json',
			data:{map:data.parameters},
			success:function(result){
				console.log(result);
				if(result.status){
					alertModal("操作成功");
					formload(result.detail);
				}
			}
		});
		
// 		$.ajax({
// 			url:'[[@{/jobInfo/save}]]',
// 			type:'POST',
// 			dataType:'json',
// 			data:data,
// 			success:function(result){
// 				console.log(result);
// 				if(result.status){
// 					alertModal("操作成功");
// 					formload(result.detail);
// 				}
// 			}
// 		});
	}
	</script>
</body>
</html>